//
//  JCWebSocketRocket.h
//  ifly
//
//  Created by Ismail on 18/9/21.
//  Copyright © 2018年 ifly. All rights reserved.
//


#import <Foundation/Foundation.h>
#import <SocketRocket.h>

typedef enum : NSUInteger {
    ConnectionTypeSuccess,  /// 连接成功
    ConnectionTypeError,  /// 连接失败
    ConnectionTypeClose,  /// 主动关闭连接
    ConnectionTypeNot  /// 未连接
} JCWebSocketConnectionType;

@class JCWebSocketRocket;
typedef void(^JCWebSocketConnectionBlock)(JCWebSocketRocket *socket, JCWebSocketConnectionType type);
typedef void(^JCReciveSuccessBlock)(JCWebSocketRocket *socket, id data);

@protocol JCWebSocketRocketDelegate <NSObject>

@optional
/**
 获取收到消息的代理
 @param message 收到的消息
 */
- (void)jcWebSocketRocket:(JCWebSocketRocket *)socket receiveMessage:(id)message;

@end

@interface JCWebSocketRocket : NSObject

/// 获取连接状态
@property (nonatomic,assign,readonly) SRReadyState socketReadyState;
@property (nonatomic, weak) id <JCWebSocketRocketDelegate> delegate;
////  连接状态
@property (nonatomic,assign,readonly) JCWebSocketConnectionType jcConnectionType;

+ (JCWebSocketRocket *)instance;
/**
开启连接

 @param urlString WebSocket 地址
 @param heartbeat 心跳包内容
 @param delegate 代理
 */
- (instancetype)initWebSocketOpenWithURLString:(NSString *)urlString withHeartbeat:(NSString *)heartbeat withDelegate:(id)delegate;
- (instancetype)initWebSocketOpenWithURLString:(NSString *)urlString withHeartbeat:(NSString *)heartbeat;

/**
  开启连接并接收数据的方法 block方法

 @param urlString WebSocket 地址
 @param heartbeat 心跳包内容
 @param connection 连接状态信息信息
 @param messCompltion 接收的数据内容
 */
+ (void)jcWebSocketOpenWithURLString:(NSString *)urlString withHeartbeat:(NSString *)heartbeat withConnection:(JCWebSocketConnectionBlock)connection withReciveMessage:(JCReciveSuccessBlock) messCompltion;
/// 关闭连接
- (void)jcWebSocketClose;
/// 发送数据
- (void)jcSendData:(id)data;
///  获取数据
- (void)jcReciveMessage:(JCReciveSuccessBlock) messCompltion;

@end
